<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// 用户登录

/**
 * 微信小程序  api
 */
Route::namespace('Wx')
     ->prefix('wx')
     ->group(function () {
         Route::post('/login', 'LoginController@login');
         Route::get('/home', 'HomeController@index');
         Route::get('/rank', 'RankController@index');
         Route::middleware('auth:wx')
              ->group(function () {
                  Route::get('/player/rank', 'PlayerController@rank');
                  Route::get('/player/statistics', 'PlayerController@statistics');
                  Route::get('/record/{id}', 'RecordController@show')
                       ->where('id', '\d+');
              });
     });

/**
 * 后台管理  admin
 */

Route::namespace('Admin')
     ->prefix('admin')
     ->group(function () {
         Route::post('/login', 'LoginController@login');
         Route::get('/search/roles', 'CommonController@getAdminRoles');
         Route::get('/season/select', 'CommonController@season');

         // 登录后可以访问的接口
         Route::middleware('auth:admin')
              ->group(function () {
                  // 玩家
                  Route::get('/players', 'PlayerController@list');
                  Route::delete('/players/{id}', 'PlayerController@delete')
                       ->where('id', '\d+');
                  Route::put('/players/{id}', 'PlayerController@update')
                       ->where('id', '\d+');
                  Route::get('/playing/players', 'PlayerController@getPlayingPlayers');

                  // 游戏角色
                  Route::get('/roles', 'CharacterController@list');
                  Route::get('/playing/roles', 'CharacterController@playing');
                  Route::post('/roles', 'CharacterController@create');
                  Route::delete('/roles/{id}', 'CharacterController@delete')
                       ->where('id', '\d+');

                  // 游戏记录
                  Route::get('/records', 'RecordController@list');
                  Route::post('/records', 'RecordController@create');
                  Route::get('/records/{id}', 'RecordController@show')
                       ->where('id', '\d+');

                  // 玩家积分
                  Route::get('/rank', 'RankController@index');
                  Route::get('/rank/{id}', 'RankController@show')
                       ->where('id', '\d+');

                  // 赛季奖励
                  Route::get('/reward', 'RewardController@list');
                  Route::post('/reward', 'RewardController@create');
                  Route::get('/reward/use', 'RewardController@getRewardUse');
                  Route::delete('/reward/use/{id}', 'RewardController@deleteRewardUse')
                       ->where('id', '\d+');
                  Route::get('/player/select', 'RewardController@getPlayerList');

                  //管理员
                  Route::post('/users', 'AdminController@create');
                  Route::get('/users', 'AdminController@index');
                  Route::get('/users/{id}', 'AdminController@show')
                       ->where('id', '\d+');
                  Route::get('/users/menus', 'AdminController@adminHasMenus');
                  Route::put('/password/{id}', 'AdminController@update')
                       ->where('id', '\d+');

                  //角色
                  Route::post('/role', 'RoleController@create');
                  Route::get('/role', 'RoleController@index');
                  Route::get('/role/{id}', 'RoleController@show')
                       ->where('id', '\d+');
                  Route::get('/role/menu', 'RoleController@menu');

                  //菜单
                  Route::post('/menu', 'MenuController@create');
                  Route::get('/menu', 'MenuController@index');
                  Route::get('/menu/{id}', 'MenuController@show')
                       ->where('id', '\d+');
              });
     });
